package com.zb.wx.controller;

import com.zb.exception.WxException;
import com.zb.result.Result;
import com.zb.service.WxPublicNoAuthorizeThirdService;
import com.zb.wx.service.ConWxService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @Author WEN
 * @Date 2024/2/29 0029
 **/
@Api(tags = "微信回调类接口")
@RestController
@RequestMapping("/wx")
//@RequestMapping("/wx/callback")
public class WxCallbackController {
    @Resource
    private ConWxService conWxService;

    @ApiOperation("获取微信第三方授权回调事件")
    @PostMapping("/thirdParty/grant/callback")
//    @PostMapping("/getThirdAuthorCallbackEvent")
    public String getWxThirdAuthorCallbackEvent(HttpServletRequest request) {
        conWxService.getWxThirdAuthorCallbackEvent(request);
        return "success";
    }

    @ApiOperation("获取微信已授权公众号消息与事件回调")
    @PostMapping("/thirdParty/{APPID}/callback")
//    @PostMapping("/authorCallbackEvent/{APPID}")
    public String getWxAuthorPubliNoMessageEventCallback(HttpServletRequest request, @PathVariable(name = "APPID") @ApiParam(value = "微信密钥appId") String appId) {
        System.out.println("appId：" + appId);
        conWxService.getWxAuthorPubliNoMessageEventCallback(request);
        return "success";
    }


    @ApiOperation("微信授权成功重定向回调")
    @GetMapping("/thirdParty/authorSuccess/redirectCallback/{uuid}")
    public Result getWxAuthorSuccessRedirectCallback(@PathVariable @ApiParam(value = "发起微信认证授权时的uuid") String uuid,
                                                   @RequestParam("auth_code") @ApiParam(value = "授权码") String authCode,
                                                   @RequestParam("expires_in") @ApiParam(value = "过期时间") Long expiresIn) throws WxException {
        conWxService.getWxAuthorSuccessRedirectCallback(authCode, expiresIn, uuid);
        return Result.success();
    }
}
